package com.czk.model.ptotorype.practice.deepcopy;



/**
 * 深拷贝的实现
 * @Author:ChenZhangKun
 * @Date: 2020/8/19 23:36
 */
public class Client {
    public static void main(String[] args) throws CloneNotSupportedException {
        // 创建person
        Person person=new Person();
        // 创建clothes
        Clothes clothes=new Clothes("red");
        person.setAge(25);
        person.setName("czk");
        person.setClothes(clothes);
        System.out.println(person);
        // 深拷贝
        Person clone = (Person) person.clone();
        System.out.println(clone);
        // 此时两个指针指向不同的内存区域
        clone.getClothes().setColor("green");
        // person的值不会随之改变
        System.out.println(person);


        // 序列化深拷贝
        Person o = (Person) person.deepClone();
        System.out.println(o);
        o.setAge(56);
        System.out.println(o);
        System.out.println(person);
    }
}
